package com.loongxun.xxapp.ui.login;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.TextView;

import com.loongxun.xxapp.R;
import com.loongxun.xxapp.ui.pass.PassChangeActivity;
import com.loongxun.xxapp.ui.pass.PassChangePhoneActivity;

/**
 * 登录界面
 * Created by Administrator on 2017/10/19.
 */
public class LoginActivity extends Activity implements View.OnClickListener{

    private SharedPreferences shared;
    private SharedPreferences.Editor editor;

    private TextView tv_title;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        findViewById(R.id.iv_back).setOnClickListener(this);
        tv_title = (TextView) findViewById(R.id.tv_title);
        tv_title.setText("登录");

        shared = getSharedPreferences("userInfo", 0);
        editor = shared.edit();//获取编辑器

        findViewById(R.id.tv_goto_register).setOnClickListener(this);
        findViewById(R.id.tv_goto_forget_pass).setOnClickListener(this);
        findViewById(R.id.tv_login).setOnClickListener(this);
    }


    @Override
    public void onClick(View view) {
        Intent intent;
        switch (view.getId()){
            case R.id.iv_back:
                finish();
                break;
            case R.id.tv_goto_register:
                intent = new Intent(this,RegisterActivity.class);
                startActivityForResult(intent, 0);
                break;
            //忘记密码
            case R.id.tv_goto_forget_pass:
                intent = new Intent(this,PassChangePhoneActivity.class);
                startActivityForResult(intent, 1);
                break;
            case R.id.tv_login:
                editor.putString("user_id", "1");
                editor.commit();//提交修改
                intent = new Intent();
                intent.putExtra("login", true);
                setResult(Activity.RESULT_OK, intent);
                finish();
                break;
            default:
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 0) {
            if (data != null){
//                CloseKeyBoard();
                Intent intent = new Intent();
                intent.putExtra("login", true);
                setResult(Activity.RESULT_OK, intent);
                finish();
            }
        }
    }

}
